<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","nokwit");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_receipt_container.php";
$FileTemplate  = "ais_transaction_receipt_container_list.html";
$TableName     = "ais_receipt";
$SubHeaderTitle= "Transaction Receipt - Container";
$PageSize      = 10 ;
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FNama = GetParam("CustomerSearch","");
//$FSkada = GetParam("skadaSearch","");
//$FDept = GetParam("deptSearch","");

//******* DATABASE FORM QUERY ***********
$SQL = "SELECT *,sum(jumlah) as sumjumlah FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";
$WHERE  = " ".QueryLedger();

//Retrieve Parameter from search

if ($FSkada) {
	$CustomWhere = " skada like '".$FSkada."%'";
	if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
	else $WHERE = $CustomWhere;
}

if ($FNama) {
	$CustomWhere = " $TableName.nama like '".$FNama."%'";
	if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
	else $WHERE = $CustomWhere;
}

if (strlen($WHERE)) {
$SQL = $SQL."WHERE ".$WHERE;
$SQLCount = $SQLCount."WHERE ".$WHERE;
}
else $SQL = $SQL;
//$SQLCount = $SQLCount." AND urut=1";
$SQL = $SQL." GROUP BY nokwit";
$SQL .= " ORDER BY tglkwit DESC, nokwit DESC";
//Select Customer 
//$SQLDept = "SELECT * FROM tbldept";
//print $SQL;
//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 
//$RecCnt = mysql_num rows($SQL);
if (!$RecCnt) $RecCnt = 0 ; 
if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
//$TBS->MergeBlock("deptblk",$DBMysql,$SQLDept);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName,$TableName;	
	for ($x=1;$x<=$PageSize;$x++) {				
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("$TableName",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>
